package com.chookss.video

import androidx.lifecycle.MutableLiveData
import com.johnrambo.ktea.base.BaseViewModel
import com.johnrambo.ktea.common.toJsonObject
import com.johnrambo.ktea.net.http.Method
import com.johnrambo.ktea.net.http.http
import org.json.JSONObject

/**
 * Create by JohnRambo at 2018/12/17
 */
class ChangePassModel : BaseViewModel() {
    val changePassLiveData by lazy { MutableLiveData<JSONObject>() }
    val errorLiveData by lazy { MutableLiveData<String>() }


    fun changePassWord(
        oldPwd: String,
        onePwd: String,
        twoPwd: String,
        timestamp: String,
        nonce: String,
        sign: String
    ) {
        jobs + http{
            url = "api/sys/my/homePage/updatePwd"
            method = Method.POST
            params = mutableMapOf(
                "oldPwd" to oldPwd,
                "onePwd" to onePwd,
                "twoPwd" to twoPwd,
                "timestamp" to timestamp,
                "nonce" to nonce,
                "sign" to sign
            )
            onSuccess = { changePassLiveData.value = it.toJsonObject() }
            onError = { errorLiveData.value = it }
        }
    }
}